<?php

class hash1 {

    public $array;

    public function __construct() {
        $this->array = new SplFixedArray(10);
    }

    public function Ha($i) {
        if (0 <= $i && $i < 10) {
            return $i;
        } else {
            return $i - 10;
        }
    }

    public function add($i) {
        if ($this->array[$this->Ha($i)] == null) {
            $linklist = new SplDoublyLinkedList();
            $linklist->push($i);
            $this->array[$this->Ha($i)] = $linklist;
        } else {
            $linklist = $this->array[$this->Ha($i)];
            $linklist->push($i);
        }
    }

    public function contain($i) {
        if ($this->array[$this->Ha($i)] == null) {
            return FALSE;
        } else {
            $linklist = $this->array[$this->Ha($i)];
            $count = $linklist->count();
            for ($j = 0; $j <= $count; $j++) {
                if($linklist->offsetGet($j)==$i){
                    return TRUE;
                }
            }
        }
    }

}

$hash1 = new hash1();
$hash1->add(2);
$hash1->add(15);
$hash1->add(12);
var_dump($hash1->array[2]->offsetGet(1));
var_dump($hash1->array[5]);
var_dump($hash1->contain(2));
var_dump($hash1->contain(15));
var_dump($hash1->contain(12));
?>
